﻿using System.Reflection;

namespace _72_C_动态加载其他程序集DLL
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string path = "TestClassLibrary.dll";
            //Load 用于加载已经在应用程序域或 GAC（全局程序集缓存）中的程序集。
            //LoadFrom 用于从指定路径加载程序集，即便程序集不在应用程序目录中。
            Assembly assembly = Assembly.LoadFrom(path);

            Type[] types = assembly.GetTypes();

            foreach (Type type in types)
            {
                Console.WriteLine($"程序集:{type.Assembly},类型名称：{type.Name}");
                Console.WriteLine("-------------");
                MethodInfo[] methods = type.GetMethods();
                foreach (MethodInfo methodInfo in methods)
                {
                    Console.WriteLine($"方法名称：{methodInfo.Name}");
                    ParameterInfo[] parameters = methodInfo.GetParameters();
                    foreach (ParameterInfo param in parameters)
                    {
                        Console.WriteLine("参数"+param.Name);
                    }
                }

                System.Reflection.FieldInfo[] fieldInfos = type.GetFields();
                foreach (FieldInfo fieldInfo in fieldInfos)
                {
                    Console.WriteLine($"字段名称：{fieldInfo.Name}");
                }
            }

            Console.ReadKey();
        }
    }
}
